/* 
输入1：/home/
输出1：/home
输入2：/../
输出2：/
输入3：/home//foo/
输出3：/home/foo
输入4：/a/./b/../../c/
输出4：/C 
*/
function simplifyPath(path) {
  const stack = [];
  const parts = path.split("/");
  console.log(parts);
  
  for (const part of parts) {
    if (part === "" || part === ".") continue;
    if (part === "..") {
      if (stack.length > 0) stack.pop();
    } else {
      stack.push(part);
    }
  }

  return "/" + stack.join("/");
}

const input = "/a/./b/../../c/";
const input1="/home//foo/"
const input2 ="/home/"
console.log(simplifyPath(input1)); // 输出: /c
